<?php

namespace app\store\model;

use think\Model;

class UserCannonModel extends Model
{
    protected $connection = 'db_platform_operatelog';

    protected $table = 'game_user_cannon_distribution';

    // 等级与数据库中的cannon保持对应
    const USER_CANNON = [
        1 => '10-90',
        2 => '100-900',
        3 => '1000-5000',
        4 => '5500-9500',
        5 => '10000-20000',
        6 => '21000-30000'
    ];

    /**
     * @param $where
     * @return array|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getUserCannonByDate($where)
    {
        $data = self::where($where)
            ->fieldRaw('cannon_dist,sum(num) as cannon_num,round(avg(num_rate),4) as num_rate,floor(avg(avg_score)) as avg_score,floor(avg(avg_diamond)) as avg_diamond')
            ->group('cannon_dist')
            ->select();

        return $data;
    }
}